﻿Public Class DRUGUNIT

    Dim connect As CONDB = CONDB.NewConnection()
    'Dim connectlocal As conlocal = conlocal.NewConnection
    Dim PROVIDER_Check As New PROVIDERSCLASS

    Private Sub DRUGUNIT_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        SelectDatagridMASUNIT()

        DesignForm(Me)
        DesignGrid(MASUNITGrid)

        PROVIDER_Check.GETHOSEM(CInt(main.txtUserRequest.Text.Trim), Convert.ToString(Me.Tag))
    End Sub

    Private Sub SelectDatagridMASUNIT()
        Dim objSelectDatamasunit As New masunit
        Dim MASUNIT As DataTable
        MASUNIT = connect.GetTable(objSelectDatamasunit.selectMasunit_)
        MASUNITGrid.PrimaryGrid.DataSource = MASUNIT
    End Sub

    Private Sub MASUNITGrid_CellClick(sender As Object, e As DevComponents.DotNetBar.SuperGrid.GridCellClickEventArgs) Handles MASUNITGrid.CellClick
        Dim grid As DevComponents.DotNetBar.SuperGrid.GridRow
        grid = e.GridPanel.ActiveRow
        'f.TXT_CID.Text = grid.Cells.Item(2).Value
        UNITIDTxt.Text = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("รหัสหน่วยนับ").Value()
        UNITNAME_ENTxt.Text = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("ชื่อหน่วยนับ(อังกฤษ)").Value()
        UNITNAME_THTxt.Text = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("ชื่อหน่วยนับ(ไทย)").Value()

        If CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("หน่วยนับยาและเวชภัณฑ์").Value() = True Then
            ckbF_rx.Checked = True
        Else
            ckbF_rx.Checked = False
        End If

        If CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("หน่วยนับlab").Value() = True Then
            ckbF_lab.Checked = True
        Else
            ckbF_lab.Checked = False
        End If

        If CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("หน่วยนับX-Ray").Value() = True Then
            ckbF_xry.Checked = True
        Else
            ckbF_xry.Checked = False
        End If

        If CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("หน่วยนับเวลา").Value() = True Then
            ckbF_time.Checked = True
        Else
            ckbF_time.Checked = False
        End If

        If CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("หน่วยนับคลัง").Value() = True Then
            ckbF_stk.Checked = True
        Else
            ckbF_stk.Checked = False
        End If

        If CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("สถานะการเปิดใช้งาน").Value() = True Then
            ckbStatus.Checked = True
        Else
            ckbStatus.Checked = False
        End If

        Dim objChkboxUpdate As New CLICKGRIDCHECKBOX
        objChkboxUpdate.clickChkboxUpdate("masunit", CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("หน่วยนับยาและเวชภัณฑ์").Value(), "f_rx", "unitid", UNITIDTxt.Text)
        objChkboxUpdate.clickChkboxUpdate("masunit", CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("หน่วยนับlab").Value(), "f_lab", "unitid", UNITIDTxt.Text)
        objChkboxUpdate.clickChkboxUpdate("masunit", CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("หน่วยนับX-Ray").Value(), "f_xry", "unitid", UNITIDTxt.Text)
        objChkboxUpdate.clickChkboxUpdate("masunit", CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("หน่วยนับเวลา").Value(), "f_time", "unitid", UNITIDTxt.Text)
        objChkboxUpdate.clickChkboxUpdate("masunit", CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("หน่วยนับคลัง").Value(), "f_stk", "unitid", UNITIDTxt.Text)
        objChkboxUpdate.clickChkboxUpdate("masunit", CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("สถานะการเปิดใช้งาน").Value(), "status", "unitid", UNITIDTxt.Text)

        editMasunit.Enabled = True
    End Sub

    Private Sub addMasunit_Click(sender As Object, e As EventArgs) Handles addMasunit.Click
        If main.PROVIDERPOLICIES.checklogin_user_ = True Then
            If PROVIDER_Check.PADD_ = True Then
                If UNITNAME_ENTxt.Text.ToString.Length > 0 And UNITNAME_THTxt.Text.ToString.Length > 0 Then
                    Dim objInsertData As New masunit
                    objInsertData.UNITNAME_EN_ = UNITNAME_ENTxt.Text
                    objInsertData.UNITNAME_TH_ = UNITNAME_THTxt.Text
                    objInsertData.F_RX_ = ckbF_rx.Checked
                    objInsertData.F_LAB_ = ckbF_lab.Checked
                    objInsertData.F_XRY_ = ckbF_xry.Checked
                    objInsertData.F_TIME_ = ckbF_time.Checked
                    objInsertData.F_STK_ = ckbF_stk.Checked
                    objInsertData.STATUS_ = ckbStatus.Checked
                    objInsertData.insertMasunitData()

                    SelectDatagridMASUNIT()
                    clearForm()
                Else
                    MsgBox("โปรดระบุข้อมูลให้ครบถ้วน")
                End If
            Else
                MsgBox(PROVIDER_Check.PADDMSG_)
            End If
        Else
            TOASTCLASS.gloadToastMSG(Me, main.PROVIDERPOLICIES.LOGINUSERMSG_)
            main.txtUserRequest.Focus()
        End If
    End Sub

    Private Sub editMasunit_Click(sender As Object, e As EventArgs) Handles editMasunit.Click
        If main.PROVIDERPOLICIES.checklogin_user_ = True Then
            If PROVIDER_Check.PUPD_ = True Then
                If UNITNAME_ENTxt.Text.ToString.Length > 0 And UNITNAME_THTxt.Text.ToString.Length > 0 Then
                    Dim editStat As Integer
                    editStat = MsgBox("ท่านต้องการแก้ไขกลุ่มผู้ให้ข้อมูลดังกล่าวใช่หรือไม่", MsgBoxStyle.OkCancel)

                    If editStat = 1 Then
                        Dim objEditData As New masunit
                        objEditData.UNITID_ = UNITIDTxt.Text
                        objEditData.UNITNAME_EN_ = UNITNAME_ENTxt.Text
                        objEditData.UNITNAME_TH_ = UNITNAME_THTxt.Text
                        objEditData.F_RX_ = ckbF_rx.Checked
                        objEditData.F_LAB_ = ckbF_lab.Checked
                        objEditData.F_XRY_ = ckbF_xry.Checked
                        objEditData.F_TIME_ = ckbF_time.Checked
                        objEditData.F_STK_ = ckbF_stk.Checked
                        objEditData.STATUS_ = ckbStatus.Checked
                        objEditData.editMasunitData()

                        SelectDatagridMASUNIT()

                        clearForm()
                    End If
                Else
                    MsgBox("โปรดระบุข้อมูลให้ครบถ้วน")
                End If
            Else
                MsgBox(PROVIDER_Check.PUPDMSG_)
            End If
        Else
            TOASTCLASS.gloadToastMSG(Me, main.PROVIDERPOLICIES.LOGINUSERMSG_)
            main.txtUserRequest.Focus()
        End If
    End Sub

    Private Sub importExel_Click(sender As Object, e As EventArgs) Handles importExel.Click
        Dim nextform As New IMPORTEXCEL("masunit")
        nextform.ShowDialog()
    End Sub

    Private Sub exportExcel_Click(sender As Object, e As EventArgs) Handles exportExcel.Click
        Dim nextform As New IMPORTEXCEL("masunit")
        nextform.ShowDialog()
    End Sub

    Public Sub clearForm()
        UNITIDTxt.Clear()
        UNITNAME_ENTxt.Text = ""
        UNITNAME_THTxt.Text = ""
        ckbF_rx.Checked = False
        ckbF_lab.Checked = False
        ckbF_xry.Checked = False
        ckbF_time.Checked = False
        ckbF_stk.Checked = False
        ckbStatus.Checked = False
    End Sub

    Private Sub btnClearForm_Click(sender As Object, e As EventArgs) Handles btnClearForm.Click
        SelectDatagridMASUNIT()
        clearForm()
    End Sub
End Class